<% if !current_settings.votes_hidden? && (current_component.participatory_space.can_participate?(current_user) || current_user.admin?) %>
  <% if component_settings.participatory_texts_enabled? && from_proposals_list %>
    <%= render partial: "decidim/proposals/proposals/participatory_texts/proposal_votes_count", locals: { proposal: resource, from_proposals_list: true } %>
  <% else %>
    <% progress ||= resource.proposal_votes_count || 0 %>
    <% total ||= resource.maximum_votes || 0 %>
    <%= cell(
          "decidim/progress_bar",
          progress,
          total:,
          units_name: "decidim.proposals.proposals.votes_count.count",
          element_id: "proposal-#{resource.id}-votes-count",
          class: total.positive? ? "card__proposals-votes-limited" : "card__proposals-votes-unlimited"
        ) %>
  <% end %>
<% end %>

<% button_classes = "button button__sm button__secondary w-full" %>

<% unless resource.rejected? || resource.withdrawn? %>
  <% if component_settings.participatory_texts_enabled? && from_proposals_list %>
    <%= render partial: "decidim/proposals/proposals/participatory_texts/proposal_vote_button", locals: { resource:, from_proposals_list: true } %>
  <% else %>
    <div id="proposal-<%= resource.id %>-vote-button" class="card__proposals-votes-container">
      <% if !current_user %>
        <% if current_settings.votes_blocked? %>
          <%= action_authorized_button_to :vote, t("decidim.proposals.proposals.vote_button.votes_blocked"), proposal_proposal_vote_path(proposal_id: resource, from_proposals_list:), resource: , class: button_classes, disabled: true, data: { "proposal-vote-button": true } %>
        <% else %>
          <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: resource, from_proposals_list:), resource: , class: button_classes, data: { "proposal-vote-button": true, disable: true, "redirect-url": proposal_path(resource) } do %>
            <%= t("decidim.proposals.proposals.vote_button.vote") %>
            <span class="sr-only"><%= decidim_html_escape(present(resource).title) %></span>
          <% end %>
        <% end %>
      <% else %>
        <% if proposal_voted_by_user?(resource) %>
          <%= action_authorized_button_to(
                :vote,
                proposal_proposal_vote_path(proposal_id: resource, from_proposals_list:),
                resource:,
                method: :delete,
                remote: true,
                data: {
                  "proposal-vote-button": true,
                  original: t("decidim.proposals.proposals.vote_button.already_voted"),
                  replace: t("decidim.proposals.proposals.vote_button.already_voted_hover"),
                  "redirect-url": proposal_path(resource)
                },
                disabled: current_settings.votes_blocked?,
                class: "#{button_classes}",
                id: "vote_button-#{resource.id}"
              ) do %>
            <%= t("decidim.proposals.proposals.vote_button.already_voted") %>
            <%= icon "check-line", class: "already-voted-icon" %>
            <span class="sr-only"><%= decidim_html_escape(present(resource).title) %></span>
          <% end %>
        <% else %>
          <% if resource.maximum_votes_reached? && !resource.can_accumulate_votes_beyond_threshold && current_component.participatory_space.can_participate?(current_user) %>
            <%= content_tag :button, t("decidim.proposals.proposals.vote_button.maximum_votes_reached"), class: button_classes, disabled: true, data: { "proposal-vote-button": true } %>
          <% else %>
            <% if vote_limit_enabled? && remaining_votes_count_for_user == 0 %>
              <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: resource, from_proposals_list:), resource: , remote: true, disabled: true, data: { "proposal-vote-button": true, "redirect-url": proposal_path(resource) }, class: button_classes do %>
                <%= t("decidim.proposals.proposals.vote_button.vote") %>
                <span class="sr-only"><%= decidim_html_escape(present(resource).title) %></span>
              <% end %>
            <% elsif current_settings.votes_blocked? || !current_component.participatory_space.can_participate?(current_user) %>
              <%= content_tag :button, t("decidim.proposals.proposals.vote_button.votes_blocked"), class: button_classes, disabled: true, data: { "proposal-vote-button": true } %>
            <% else %>
              <%= action_authorized_button_to :vote, proposal_proposal_vote_path(proposal_id: resource, from_proposals_list:), resource: , remote: true, data: { "proposal-vote-button": true, "redirect-url": proposal_path(resource) }, class: button_classes do %>
                <%= t("decidim.proposals.proposals.vote_button.vote") %>
                <span class="sr-only"><%= decidim_html_escape(present(resource).title) %></span>
              <% end %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>
    </div>
  <% end %>
<% end %>
